Locks the door whose own door_id is door: it stops sending (acting as an Enter door) until unlocked. door may be the door’s own name (given it in the Room Editor) - resolved to its door_id at compile time, for free - or a door_id int, literal or computed.
door_lock(door)| Name | Type |
|---|---|
door | door |
Nothing.
Locks the door whose own door_id is door: it stops sending (acting as an Enter door) until door_unlock is called on the same door_id.
A door's own state - door_id, locked, door_mode - lives as ordinary instance variables on whichever object the editor's Room Editor placed it with (its "+ Add Door" wizard makes one per distinct triggering object). door_lock/door_unlock/door_is_locked/door_set_mode/door_mode find that instance by its door_id - a plain int, project-wide unique, shown in the editor's own Doors list - so a lever, a switch, or any other instance can lock or unlock a door it holds no reference to at all, target first, the same argument order tile_set_class(x, y, cls) already uses.
door accepts either a door's own NAME or its door_id. If a door was given a name in the Room Editor's Configure dialog, write that name directly - door_lock(front_gate) - and it resolves to the door's own door_id at compile time, for free (the same way a bare room name resolves in room_change(room)). An unnamed door, or one addressed remotely with no name handy, still works exactly as before: a literal door_id (door_lock(3)), or any ordinary int expression - a variable, d.door_id off a held reference, anything. A door name that does not exist (misspelled, or a door since deleted) fails the build, naming the identifier - never a call that compiles and does nothing at runtime, which is the risk a hardcoded door_id still carries if that door is ever deleted.
Locked blocks SENDING only. A locked door still works as an Exit - it can still be arrived at; see door_is_locked for why that matters before writing code that assumes otherwise.
Addressing a door this way is not the only option: instance_nearest(x, y, obj_door_obj_player) already reaches a NEARBY door's own locked variable directly with no function call at all. door_lock earns its place for the case that cannot: a door with no reference to it in scope - a switch unlocking a gate across the room, or in a room the switch cannot see into.
if (btn_pressed(BTN_A)) {
door_lock(3);
}Locks the door whose door_id is 3 - shown in the editor's Doors list for whichever door was given that id - the moment A is pressed. It no longer sends (acts as an Enter door); anything still targeting it as an Exit still arrives fine.
A door instance is never persistent, so it is cleared along with the rest of its own room the moment that room is no longer current. door_lock only ever finds a door that is a live instance in the current room right now - a door_id belonging to a different room is not found, and the call is a harmless no-op, never a crash and never a write to the wrong door.
Locked blocks SENDING ONLY - a locked door still works as an Exit (still receives, still a valid arrival target); see door_is_locked for why that matters. A no-op if door names no LIVE door instance right now (not this room’s own door_id, or not a door at all) - see this group’s own header for the current-room-only limit. A door NAME that no longer exists (unknown, or deleted in the editor) is a compile error naming it, not a silent no-op - only an int door_id can go stale like that at runtime.